package com.sdb.docters.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.sdb.docters.dto.Departmentvo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sdb.common.annotation.Log;
import com.sdb.common.core.controller.BaseController;
import com.sdb.common.core.domain.AjaxResult;
import com.sdb.common.enums.BusinessType;
import com.sdb.docters.domain.TdDocters;
import com.sdb.docters.service.ITdDoctersService;
import com.sdb.common.utils.poi.ExcelUtil;
import com.sdb.common.core.page.TableDataInfo;

/**
 * 医生信息Controller
 * 
 * @author yyh
 * @date 2024-12-26
 */
@RestController
@RequestMapping("/docters/docterlist")
public class TdDoctersController extends BaseController
{
    @Autowired
    private ITdDoctersService tdDoctersService;

    /**
     * 查询医生信息列表
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @GetMapping("/list")
    public TableDataInfo list(TdDocters tdDocters)
    {
        startPage();
        List<TdDocters> list = tdDoctersService.selectTdDoctersList(tdDocters);
        return getDataTable(list);
    }

    /**
     * 查询未绑定账号医生信息列表
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @GetMapping("/docterlist")
    public TableDataInfo docterlist(TdDocters tdDocters)
    {
        startPage();
        List<TdDocters> list = tdDoctersService.nouserDocterlist(tdDocters);
        return getDataTable(list);
    }

    /**
     * 导出医生信息列表
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @Log(title = "医生信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TdDocters tdDocters)
    {
        List<TdDocters> list = tdDoctersService.selectTdDoctersList(tdDocters);
        ExcelUtil<TdDocters> util = new ExcelUtil<TdDocters>(TdDocters.class);
        util.exportExcel(response, list, "医生信息数据");
    }

    /**
     * 获取医生信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @GetMapping(value = "/{docterId}")
    public AjaxResult getInfo(@PathVariable("docterId") Long docterId)
    {
        return success(tdDoctersService.selectTdDoctersByDocterId(docterId));
    }

    /**
     * 新增医生信息
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @Log(title = "医生信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TdDocters tdDocters)
    {
        return toAjax(tdDoctersService.insertTdDocters(tdDocters));
    }

    /**
     * 修改医生信息
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @Log(title = "医生信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TdDocters tdDocters)
    {
        return toAjax(tdDoctersService.updateTdDocters(tdDocters));
    }

    /**
     * 删除医生信息
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @Log(title = "医生信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{docterIds}")
    public AjaxResult remove(@PathVariable Long[] docterIds)
    {
        return toAjax(tdDoctersService.deleteTdDoctersByDocterIds(docterIds));
    }

    /**
     * 获取科室列表
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @Log(title = "科室列表", businessType = BusinessType.OTHER)
    @GetMapping("/departlist")
    public List<Departmentvo> departlist()
    {
        return tdDoctersService.departlist();
    }

    /**
     * 根据科室获取医生列表
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @GetMapping("/listbydept")
    public List<TdDocters> docterlistbydept(TdDocters tdDocters)
        {
            return tdDoctersService.docterlistbydept(tdDocters);
        }
}
